//
//  SetVC.m
//  HappyRent
//
//  Created by CoderYee on 2017/3/29.
//  Copyright © 2017年 内圈科技. All rights reserved.
//

#import "SetVC.h"
#import "Set_layoutTableViewCell.h"   //退出登录
#import "Set_About_VC.h"             //关于我们
#import "YeeCacheManger.h"
@interface SetVC ()<BaseTableViewCelldelegate>
{
    NSString   *_cachestring;
    
}
@end

@implementation SetVC

-(void)addNavbarView{
    
    self.title=@"设置";
}
-(void)configOwnViews{
    _cachestring=@"计算中...";
    [self getCacheSize];
}
-(void)registerCellClass{
    [super registerCellClass];
    [self.tableView registerClass:[Set_layoutTableViewCell class] forCellReuseIdentifier:[Set_layoutTableViewCell cellIdentifier]];
}
#pragma mark  UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return section==0?4:1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
       
        BaseTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:[BaseTableViewCell cellIdentifier] forIndexPath:indexPath];
        [cell configTableCellindexPath:indexPath];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.textColor=kGrayColor;
        cell.textLabel.font=systemfont(16);
        NSArray *titleArray=@[@"账号安全",@"清除缓存",@"通知管理",@"关于我们"];
        cell.textLabel.text=titleArray[indexPath.row];
        if (indexPath.row==1) {
            UILabel *rightLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 13, kMainScreenWidth-120, 21)];
            rightLable.font=systemfont(13);
            rightLable.textColor=kGrayColor;
            rightLable.textAlignment=NSTextAlignmentRight;
            rightLable.text=_cachestring;
            cell.accessoryView=rightLable;
        }
        return cell;
    }else{
        
        Set_layoutTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:[Set_layoutTableViewCell cellIdentifier] forIndexPath:indexPath];
        cell.delegate=self;
        return cell;
    }
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *view=[[UIView alloc] init];
    return view;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, 0.01)];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 18.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
#pragma mark  BaseTableViewCelldelegate
-(void)clickTableView:(BaseTableViewCell*)tableCell withEventType:(TableClickEvent)eventValue{
    
    
}
#pragma mark
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
     
        
    }else if (indexPath.row==1){
      
        Set_About_VC *VC=[Set_About_VC new];
        [self.navigationController pushViewController:VC animated:YES];
    }
    
}
-(void)getCacheSize
{
    [[YeeCacheManger manger] getCacheSizeSuccessBlock:^(CGFloat cacheSize)
     {
         if (cacheSize < 1024)
         {
             _cachestring = @"0.0k";
         } else if (1024 > cacheSize && cacheSize < 1024 * 1024)
         {
             _cachestring = [NSString stringWithFormat:@"%0.2fk",cacheSize/1024.0];
         } else
         {
             _cachestring =[NSString stringWithFormat:@"%0.2fM",cacheSize/1024.0/1024.0];
         }
         [self.tableView reloadData];
     } failBlock:^(NSError *error)
     {
         
     }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
